<?php
/**
 * Created by mww
 * User: mww
 */

namespace app\admin\controller;
use think\Db;
use think\Request;

class Picture extends Base
{
    /**
     * 企业数据
     */
    public function company(){
        extract(input());
        //医生分布（和企业无关）
        $whereUserMap = [
            'user_status' => 1,
            'user_verify' => 2,
            'user_type' => 1,
            'pid' => ['>',0],
        ];
        //资料浏览和互动1（产品咨询和项目咨询）
        $whereDataSee = []; //暂时和产品咨询和项目咨询通用
        //互动2 3 4
        $whereUserTalkQuestion = [
            'user_type' => 2,
            'dqr_show' => 1
        ];
        $whereUserTalkMeet = [
            'user_type' => 2,
        ];
        $whereUserTalkSae = [
            'user_type' => 2,
        ];
        //提问数
        $whereDataQues = [];
        //报告数
        $whereSae = [];
        //会议
        $whereMeet = [];
        //---session区分总后台和企业后台 start ------
        if(session("company_id") > 0){
            $c_id = session("company_id");
            $whereDataSee['c.c_id'] = $c_id;
            $whereUserTalkQuestion['c.c_id'] = $c_id;
            $whereUserTalkMeet['c.c_id'] = $c_id;
            $whereUserTalkSae['c.c_id'] = $c_id;
            $whereDataQues['c.c_id'] = $c_id;
            $whereSae['c.c_id'] = $c_id;
            $whereMeet['user_hospital'] = $c_id;
        }
        //---session区分总后台和企业后台 end ------
        $keyword = input('keyword');
        $start = input('start');
        $end = input('end');
        if(isset($keyword) && $keyword){
            $whereDataSee['c_name'] = ['like',"%$keyword%"];
            $whereUserTalkQuestion['c_name'] = ['like',"%$keyword%"];
            $whereUserTalkMeet['c_name'] = ['like',"%$keyword%"];
            $whereUserTalkSae['c_name'] = ['like',"%$keyword%"];
            $whereDataQues['c_name'] = ['like',"%$keyword%"];
            $whereSae['c_name'] = ['like',"%$keyword%"];
            $whereMeet['c_name'] = ['like',"%$keyword%"];
        }
        //时间查询
        if(isset($start) && $start)
        {
            $whereUserMap['user_time'] = ['>=',$start . ' 00:00:00'];
            $whereDataSee['date'] = ['>=',$start];
            $whereUserTalkQuestion['dqr_time'] = ['>=',$start . ' 00:00:00'];
            $whereUserTalkMeet['mq_time'] = ['>=',$start . ' 00:00:00'];
            $whereUserTalkSae['sr_time'] = ['>=',$start . ' 00:00:00'];
            $whereDataQues['dq_time'] = ['>=',$start . ' 00:00:00'];
            $whereSae['sae_time'] = ['>=',$start . ' 00:00:00'];
            $whereMeet['m_time'] = ['>=',$start . ' 00:00:00'];
        }
        if(isset($end) && $end)
        {
            $whereUserMap['user_time'] = ['<=',$end . ' 23:59:59'];
            $whereDataSee['date'] = ['<=',$end];
            $whereUserTalkQuestion['dqr_time'] = ['<=',$end . ' 23:59:59'];
            $whereUserTalkMeet['mq_time'] = ['<=',$end . ' 23:59:59'];
            $whereUserTalkSae['sr_time'] = ['<=',$end . ' 23:59:59'];
            $whereDataQues['dq_time'] = ['<=',$end . ' 23:59:59'];
            $whereSae['sae_time'] = ['<=',$end . ' 23:59:59'];
            $whereMeet['m_time'] = ['<=',$end . ' 23:59:59'];
        }
        if(isset($start) && $start && isset($end) && $end)
        {
            $whereUserMap['user_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereDataSee['date'] = ['between',[$start,$end]];
            $whereUserTalkQuestion['dqr_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereUserTalkMeet['mq_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereUserTalkSae['sr_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereDataQues['dq_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereSae['sae_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereMeet['m_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
        }
        //-------------------------------------------------------------------------------------------------------------
        $userMap = Db::table('up_u_user u')
            ->join('up_area a','u.user_shi = a.district_id','left')
            ->where($whereUserMap)
            ->group('user_shi')
            ->field('count(user_id) value,district,pid,district_id,lon,lat')
            ->select();
        $pid = array_column ($userMap,'pid');
        $userMapData = [];
        $userGeoCoordMap = [];
        $userNum = 0;
        if($userMap){
            $fnames = Db::table('up_area')->where('district_id','in',$pid)->column('district');
            foreach($userMap as $key=>$vo){
                $userNum += $vo['value'];
                $userMapData[] = ['name'=>$vo['district'],'value'=>$vo['value']];
                if($vo['lon'] && $vo['lat']){
                    $userGeoCoordMap[$vo['district']] = [$vo['lon'],$vo['lat']];
                }else{
                    $fname = $fnames[$key];
                    $url = "https://restapi.amap.com/v3/geocode/geo?output=JSON&key=5cde172b572d560a1946eb0dea85834d&address=".$fname.$vo['district'];//高德地图
                    $result=https_request($url);
                    $place = explode (',',json_decode($result, true)['geocodes'][0]['location']);
                    $userGeoCoordMap[$vo['district']] = $place;
                    Db::table('up_area')->where('district_id',$vo['district_id'])->update(['lon'=>$place[0],'lat'=>$place[1]]);
                }
            }
        }
        $this->assign('userMapData',json_encode($userMapData));
        $this->assign('userGeoCoordMap',json_encode($userGeoCoordMap));
        $this->assign('userNum',$userNum);
        unset($whereUserMap['pid']);
        //-----性别-----
        $userSex1 = Db::table('up_u_user')
            ->where($whereUserMap)
            ->where('user_sex',1)
            ->count();
        $userSex2 = Db::table('up_u_user')
            ->where($whereUserMap)
            ->where('user_sex',2)
            ->count();
        $userSex = [
            ['value' => $userSex1,'name' => '男'],
            ['value' => $userSex2,'name' => '女']
        ];
        $this->assign('userSex',json_encode($userSex));
        //-----职称-----
        $userJobName = Db::table('up_u_user')
            ->where($whereUserMap)
            ->group('user_job_desc')
            ->column('user_job_desc');
        $userJobValue = Db::table('up_u_user')
            ->where($whereUserMap)
            ->group('user_job_desc')
            ->column('count(user_id)');
        $this->assign('userJobName',json_encode($userJobName));
        $this->assign('userJobValue',json_encode($userJobValue));
        //-----科室-----
        $userRoomName = Db::table('up_u_user')
            ->where($whereUserMap)
            ->group('user_room')
            ->column('user_room');
        $userRoomValue = Db::table('up_u_user')
            ->where($whereUserMap)
            ->group('user_room')
            ->column('count(user_id)');
        $this->assign('userRoomName',json_encode($userRoomName));
        $this->assign('userRoomValue',json_encode($userRoomValue));
        //-----------------------------------------------------------------------------------------------------------
        //-----资料浏览次数-----
        $dataSee = Db::table('up_zz_history zzh')
            ->join('up_company c','zzh.c_id = c.c_id','left')
            ->where($whereDataSee)
            ->sum('times');
        $this->assign('dataSee',$dataSee);
        //-----医生企业代表互动次数-----
        $userTalk1 = Db::table('up_zz_friend zzf')
            ->join('up_company c','zzf.c_id = c.c_id','left')
            ->where($whereDataSee)
            ->sum('times');
        $userTalkQ = Db::table('up_company_pd_question_reply r')
            ->join('up_u_user u','r.dqr_user_id = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->where($whereUserTalkQuestion)
            ->count();
        $userTalkM = Db::table('up_meeting_question q')
            ->join('up_u_user u','q.mq_user_id = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->where($whereUserTalkMeet)
            ->count();
        $userTalkSae = Db::table('up_sae_reply s')
            ->join('up_u_user u','s.sr_user_id = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->where($whereUserTalkSae)
            ->count();
        $userTalk = $userTalk1 + $userTalkQ + $userTalkM + $userTalkSae;
        $this->assign('userTalk',$userTalk);
        //-------医生资料咨询数量-------
        $dataQues = Db::table('up_company_pd_question q')
            ->join('up_u_user u','q.dq_get_uid = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->where($whereDataQues)
            ->count();
        $this->assign('dataQues',$dataQues);
        //-------sae报告数量-------
        $dataSae = Db::table('up_sae s')
            ->join('up_company c','s.sae_c_id = c.c_id','left')
            ->where($whereSae)
            ->count();
        $this->assign('dataSae',$dataSae);
        //-------会议数量和会议时长-------
        $meetCount = Db::table('up_meeting m')
            ->join('up_u_user u','m.m_user_id = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->where($whereMeet)
            ->count();
        $this->assign('meetCount',$meetCount);
        $meetTimesData = Db::table('up_meeting m')
            ->join('up_u_user u','m.m_user_id = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->where($whereMeet)
            ->field('sum(UNIX_TIMESTAMP(m_end) - UNIX_TIMESTAMP(m_start)) timeLess')
            ->find();
        if($meetTimesData['timeLess'] && $meetTimesData['timeLess'] > 0){
            $meetTimes = (int)($meetTimesData['timeLess']/60);
        }else{
            $meetTimes = 0;
        }
        $this->assign('meetTimes',$meetTimes);
//        dump($userJobName);
//        dump($userJobValue);
//        die;
        $this->assign('keyword',$keyword);
        $this->assign('start',$start);
        $this->assign('end',$end);
        return $this->fetch();
    }
    /**
     * 产品数据
     */
    public function product(){
        extract(input());
        //医生分布（和企业无关）
        $whereUserMap = [
            'user_status' => 1,
            'user_verify' => 2,
            'user_type' => 1,
            'pid' => ['>',0],
        ];
        //资料浏览和互动1（产品咨询）
        $whereDataSee = []; //暂时和产品咨询和项目咨询通用
        //互动
        $whereUserTalkQuestion = [
            'user_type' => 2,
            'dqr_show' => 1
        ];
        //提问数
        $whereDataQues = [];
        //报告数
        $whereSae = [];
        //---session区分总后台和企业后台 start ------
        if(session("company_id") > 0){
            $c_id = session("company_id");
            $whereDataSee['c.c_id'] = $c_id;
            $whereUserTalkQuestion['c.c_id'] = $c_id;
            $whereDataQues['c.c_id'] = $c_id;
            $whereSae['c.c_id'] = $c_id;
        }
        //---session区分总后台和企业后台 end ------
        $keyword = input('keyword');
        $start = input('start');
        $end = input('end');
        if(isset($keyword) && $keyword){
            $whereDataSee['cp.cp_name'] = ['like',"%$keyword%"];
            $whereUserTalkQuestion['cp.cp_name'] = ['like',"%$keyword%"];
            $whereDataQues['cp.cp_name'] = ['like',"%$keyword%"];
            $whereSae['cp.cp_name'] = ['like',"%$keyword%"];
        }
        //时间查询
        if(isset($start) && $start)
        {
            $whereUserMap['user_time'] = ['>=',$start . ' 00:00:00'];
            $whereDataSee['date'] = ['>=',$start];
            $whereUserTalkQuestion['dqr_time'] = ['>=',$start . ' 00:00:00'];
            $whereDataQues['dq_time'] = ['>=',$start . ' 00:00:00'];
            $whereSae['sae_time'] = ['>=',$start . ' 00:00:00'];
        }
        if(isset($end) && $end)
        {
            $whereUserMap['user_time'] = ['<=',$end . ' 23:59:59'];
            $whereDataSee['date'] = ['<=',$end];
            $whereUserTalkQuestion['dqr_time'] = ['<=',$end . ' 23:59:59'];
            $whereDataQues['dq_time'] = ['<=',$end . ' 23:59:59'];
            $whereSae['sae_time'] = ['<=',$end . ' 23:59:59'];
        }
        if(isset($start) && $start && isset($end) && $end)
        {
            $whereUserMap['user_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereDataSee['date'] = ['between',[$start,$end]];
            $whereUserTalkQuestion['dqr_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereDataQues['dq_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereSae['sae_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
        }
        //-------------------------------------------------------------------------------------------------------------
        $userMap = Db::table('up_u_user u')
            ->join('up_area a','u.user_shi = a.district_id','left')
            ->where($whereUserMap)
            ->group('user_shi')
            ->field('count(user_id) value,district,pid,district_id,lon,lat')
            ->select();
        $pid = array_column ($userMap,'pid');
        $userMapData = [];
        $userGeoCoordMap = [];
        $userNum = 0;
        if($userMap){
            $fnames = Db::table('up_area')->where('district_id','in',$pid)->column('district');
            foreach($userMap as $key=>$vo){
                $userNum += $vo['value'];
                $userMapData[] = ['name'=>$vo['district'],'value'=>$vo['value']];
                if($vo['lon'] && $vo['lat']){
                    $userGeoCoordMap[$vo['district']] = [$vo['lon'],$vo['lat']];
                }else{
                    $fname = $fnames[$key];
                    $url = "https://restapi.amap.com/v3/geocode/geo?output=JSON&key=5cde172b572d560a1946eb0dea85834d&address=".$fname.$vo['district'];//高德地图
                    $result=https_request($url);
                    $place = explode (',',json_decode($result, true)['geocodes'][0]['location']);
                    $userGeoCoordMap[$vo['district']] = $place;
                    Db::table('up_area')->where('district_id',$vo['district_id'])->update(['lon'=>$place[0],'lat'=>$place[1]]);
                }
            }
        }
        $this->assign('userMapData',json_encode($userMapData));
        $this->assign('userGeoCoordMap',json_encode($userGeoCoordMap));
        $this->assign('userNum',$userNum);
        unset($whereUserMap['pid']);
        //-----性别-----
        $userSex1 = Db::table('up_u_user')
            ->where($whereUserMap)
            ->where('user_sex',1)
            ->count();
        $userSex2 = Db::table('up_u_user')
            ->where($whereUserMap)
            ->where('user_sex',2)
            ->count();
        $userSex = [
            ['value' => $userSex1,'name' => '男'],
            ['value' => $userSex2,'name' => '女']
        ];
        $this->assign('userSex',json_encode($userSex));
        //-----职称-----
        $userJobName = Db::table('up_u_user')
            ->where($whereUserMap)
            ->group('user_job_desc')
            ->column('user_job_desc');
        $userJobValue = Db::table('up_u_user')
            ->where($whereUserMap)
            ->group('user_job_desc')
            ->column('count(user_id)');
        $this->assign('userJobName',json_encode($userJobName));
        $this->assign('userJobValue',json_encode($userJobValue));
        //-----科室-----
        $userRoomName = Db::table('up_u_user')
            ->where($whereUserMap)
            ->group('user_room')
            ->column('user_room');
        $userRoomValue = Db::table('up_u_user')
            ->where($whereUserMap)
            ->group('user_room')
            ->column('count(user_id)');
        $this->assign('userRoomName',json_encode($userRoomName));
        $this->assign('userRoomValue',json_encode($userRoomValue));
        //-----------------------------------------------------------------------------------------------------------
        //-----资料浏览次数-----
        $dataSee = Db::table('up_zz_history zzh')
            ->join('up_company c','zzh.c_id = c.c_id','left')
            ->join('up_company_product cp','zzh.p_id = cp.cp_id','left')
            ->where($whereDataSee)
            ->sum('times');
        $this->assign('dataSee',$dataSee);
        //-----医生企业代表互动次数-----
        $userTalk1 = Db::table('up_zz_friend zzf')
            ->join('up_company c','zzf.c_id = c.c_id','left')
            ->join('up_company_product cp','zzf.p_id = cp.cp_id','left')
            ->where($whereDataSee)
            ->where('type',1)
            ->sum('times');
        $userTalkQ = Db::table('up_company_pd_question_reply r')
            ->join('up_u_user u','r.dqr_user_id = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->join('up_company_pd_question q','r.dqr_dq_id = q.dq_id','left')
            ->join('up_company_product_data da','q.dq_cpd_id = da.cpd_id','left')
            ->join('up_company_product cp','da.cpd_cp_id = cp.cp_id','left')
            ->where($whereUserTalkQuestion)
            ->count();
        $userTalk = $userTalk1 + $userTalkQ;
        $this->assign('userTalk',$userTalk);
        //-------医生资料咨询数量-------
        $dataQues = Db::table('up_company_pd_question q')
            ->join('up_u_user u','q.dq_get_uid = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->join('up_company_product_data da','q.dq_cpd_id = da.cpd_id','left')
            ->join('up_company_product cp','da.cpd_cp_id = cp.cp_id','left')
            ->where($whereDataQues)
            ->count();
        $this->assign('dataQues',$dataQues);
        //-------sae报告数量-------
        $dataSae = Db::table('up_sae s')
            ->join('up_company c','s.sae_c_id = c.c_id','left')
            ->join('up_company_product cp','s.sae_cp_id = cp.cp_id','left')
            ->where($whereSae)
            ->count();
        $this->assign('dataSae',$dataSae);
        $this->assign('keyword',$keyword);
        $this->assign('start',$start);
        $this->assign('end',$end);
        return $this->fetch();
    }
    /**
     * 文件数据
     */
    public function cpdshow(){
        extract(input());
        //医生分布（和企业无关）
        $whereUserMap = [
            'u.user_status' => 1,
            'u.user_type' => 1,
            'pid' => ['>',0],
        ];
        //资料浏览和互动1（产品咨询）
        $whereDataSee = []; //暂时和产品咨询和项目咨询通用
        //互动
        $whereUserTalkQuestion = [
            'user_type' => 2,
            'dqr_show' => 1
        ];
        //提问数
        $whereDataQues = [];
        //---session区分总后台和企业后台 start ------
        if(session("company_id") > 0){
            $c_id = session("company_id");
            $whereUserMap['c.c_id'] = $c_id;
            $whereDataSee['c.c_id'] = $c_id;
            $whereUserTalkQuestion['c.c_id'] = $c_id;
            $whereDataQues['c.c_id'] = $c_id;
        }
        //---session区分总后台和企业后台 end ------
        $keyword = input('keyword');
        $start = input('start');
        $end = input('end');
        if(isset($keyword) && $keyword){
            $whereUserMap['da.cpd_name'] = ['like',"%$keyword%"];
            $whereUserTalkQuestion['da.cpd_name'] = ['like',"%$keyword%"];
            $whereDataQues['da.cpd_name'] = ['like',"%$keyword%"];
        }
        $whereUserMap2 = $whereUserMap;
        $whereUserMap3 = $whereUserMap;
        //时间查询
        if(isset($start) && $start)
        {
            $whereUserMap['date'] = ['>=',$start];
            $whereUserMap2['dq_time'] = ['>=',$start . ' 00:00:00'];
            $whereUserMap3['cpd_time'] = ['>=',$start . ' 00:00:00'];
            $whereDataSee['date'] = ['>=',$start];
            $whereUserTalkQuestion['dqr_time'] = ['>=',$start . ' 00:00:00'];
            $whereDataQues['dq_time'] = ['>=',$start . ' 00:00:00'];
        }
        if(isset($end) && $end)
        {
            $whereUserMap['date'] = ['<=',$end];
            $whereUserMap2['dq_time'] = ['<=',$end . ' 23:59:59'];
            $whereUserMap3['cpd_time'] = ['<=',$end . ' 23:59:59'];
            $whereDataSee['date'] = ['<=',$end];
            $whereUserTalkQuestion['dqr_time'] = ['<=',$end . ' 23:59:59'];
            $whereDataQues['dq_time'] = ['<=',$end . ' 23:59:59'];
        }
        if(isset($start) && $start && isset($end) && $end)
        {
            $whereUserMap['date'] = ['between',[$start,$end]];
            $whereUserMap2['dq_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereUserMap3['cpd_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereDataSee['date'] = ['between',[$start,$end]];
            $whereUserTalkQuestion['dqr_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
            $whereDataQues['dq_time'] = ['between',[$start . ' 00:00:00',$end . ' 23:59:59']];
        }
        $whereUserMap3['u.user_type'] = 2;
        //--------------------------------------------111111111-----------------------------------------------------------------
        $userMap = Db::table('up_zz_history h')
            ->join('up_company c','h.c_id = c.c_id','left')
            ->join('up_company_product_data da','h.d_id = da.cpd_id','left')
            ->join('up_u_user u','h.c_user_id = u.user_id','left')
            ->join('up_area a','u.user_shi = a.district_id','left')
            ->where($whereUserMap)
            ->group('user_shi')
            ->field('count(user_id) value,district,pid,district_id,lon,lat')
            ->select();
        $pid = array_column ($userMap,'pid');
        $userMapData = [];
        $userGeoCoordMap = [];
        $userNum = 0;
        if($userMap){
            $fnames = Db::table('up_area')->where('district_id','in',$pid)->column('district');
            foreach($userMap as $key=>$vo){
                $userNum += $vo['value'];
                $userMapData[] = ['name'=>$vo['district'],'value'=>$vo['value']];
                if($vo['lon'] && $vo['lat']){
                    $userGeoCoordMap[$vo['district']] = [$vo['lon'],$vo['lat']];
                }else{
                    $fname = $fnames[$key];
                    $url = "https://restapi.amap.com/v3/geocode/geo?output=JSON&key=5cde172b572d560a1946eb0dea85834d&address=".$fname.$vo['district'];//高德地图
                    $result=https_request($url);
                    $place = explode (',',json_decode($result, true)['geocodes'][0]['location']);
                    $userGeoCoordMap[$vo['district']] = $place;
                    Db::table('up_area')->where('district_id',$vo['district_id'])->update(['lon'=>$place[0],'lat'=>$place[1]]);
                }
            }
        }
        $this->assign('userMapData',json_encode($userMapData));
        $this->assign('userGeoCoordMap',json_encode($userGeoCoordMap));
        $this->assign('userNum',$userNum);
        //-----------------------------------------------------------------------------------------------------------
        //----------------------------------------------22222222222---------------------------------------------------------------
        $userMap2 = Db::table('up_company_pd_question q')
            ->join('up_u_user u','q.dq_send_uid = u.user_id','left') //医生
            ->join('up_area a','u.user_shi = a.district_id','left')
            ->join('up_u_user u2','q.dq_get_uid = u2.user_id','left')
            ->join('up_company c','u2.user_hospital = c.c_id','left')
            ->join('up_company_product_data da','q.dq_cpd_id = da.cpd_id','left')
            ->where($whereUserMap2)
            ->group('u.user_shi')
            ->field('count(*) value,district,pid,district_id,lon,lat')
            ->select();
        $pid = array_column ($userMap2,'pid');
        $userMapData2 = [];
        $userGeoCoordMap2 = [];
        $userNum2 = 0;
        if($userMap2){
            $fnames = Db::table('up_area')->where('district_id','in',$pid)->column('district');
            foreach($userMap2 as $key=>$vo){
                $userNum2 += $vo['value'];
                $userMapData2[] = ['name'=>$vo['district'],'value'=>$vo['value']];
                if($vo['lon'] && $vo['lat']){
                    $userGeoCoordMap2[$vo['district']] = [$vo['lon'],$vo['lat']];
                }else{
                    $fname = $fnames[$key];
                    $url = "https://restapi.amap.com/v3/geocode/geo?output=JSON&key=5cde172b572d560a1946eb0dea85834d&address=".$fname.$vo['district'];//高德地图
                    $result=https_request($url);
                    $place = explode (',',json_decode($result, true)['geocodes'][0]['location']);
                    $userGeoCoordMap2[$vo['district']] = $place;
                    Db::table('up_area')->where('district_id',$vo['district_id'])->update(['lon'=>$place[0],'lat'=>$place[1]]);
                }
            }
        }
        $this->assign('userMapData2',json_encode($userMapData2));
        $this->assign('userGeoCoordMap2',json_encode($userGeoCoordMap2));
        $this->assign('userNum2',$userNum2);
        //-----------------------------------------------------------------------------------------------------------
        //----------------------------------------------3333333333333---------------------------------------------------------------
        $userMap3 = Db::table('up_company_product_data da')
            ->join('up_company_product p','da.cpd_cp_id = p.cp_id','left')
            ->join('up_company c','p.cp_c_id = c.c_id','left')
            ->join('up_u_user u','p.cp_charge_uid = u.user_id','left') //医生
            ->join('up_area a','u.user_shi = a.district_id','left')
            ->where($whereUserMap3)
            ->group('u.user_shi')
            ->field('count(*) value,district,pid,district_id,lon,lat')
            ->select();
        $pid = array_column ($userMap3,'pid');
        $userMapData3 = [];
        $userGeoCoordMap3 = [];
        $userNum3 = 0;
        if($userMap3){
            $fnames = Db::table('up_area')->where('district_id','in',$pid)->column('district');
            foreach($userMap3 as $key=>$vo){
                $userNum3 += $vo['value'];
                $userMapData3[] = ['name'=>$vo['district'],'value'=>$vo['value']];
                if($vo['lon'] && $vo['lat']){
                    $userGeoCoordMap3[$vo['district']] = [$vo['lon'],$vo['lat']];
                }else{
                    @$fname = $fnames[$key];
                    $url = "https://restapi.amap.com/v3/geocode/geo?output=JSON&key=5cde172b572d560a1946eb0dea85834d&address=".$fname.$vo['district'];//高德地图
                    $result=https_request($url);
                    $place = explode (',',json_decode($result, true)['geocodes'][0]['location']);
                    $userGeoCoordMap3[$vo['district']] = $place;
                    Db::table('up_area')->where('district_id',$vo['district_id'])->update(['lon'=>$place[0],'lat'=>$place[1]]);
                }
            }
        }
        $this->assign('userMapData3',json_encode($userMapData3));
        $this->assign('userGeoCoordMap3',json_encode($userGeoCoordMap3));
        $this->assign('userNum3',$userNum3);
        //-----------------------------------------------------------------------------------------------------------
        //-----医生企业代表互动次数-----
        $userTalk1 = Db::table('up_zz_friend zzf')
            ->join('up_company c','zzf.c_id = c.c_id','left')
            ->join('up_company_product cp','zzf.p_id = cp.cp_id','left')
            ->where($whereDataSee)
            ->where('type',1)
            ->sum('times');
        $userTalkQ = Db::table('up_company_pd_question_reply r')
            ->join('up_u_user u','r.dqr_user_id = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->join('up_company_pd_question q','r.dqr_dq_id = q.dq_id','left')
            ->join('up_company_product_data da','q.dq_cpd_id = da.cpd_id','left')
            ->where($whereUserTalkQuestion)
            ->count();
        $userTalk = $userTalk1 + $userTalkQ;
        $this->assign('userTalk',$userTalk);
        //-------医生资料咨询数量-------
        $dataQues = Db::table('up_company_pd_question q')
            ->join('up_u_user u','q.dq_get_uid = u.user_id','left')
            ->join('up_company c','u.user_hospital = c.c_id','left')
            ->join('up_company_product_data da','q.dq_cpd_id = da.cpd_id','left')
            ->where($whereDataQues)
            ->count();
        $this->assign('dataQues',$dataQues);

        $this->assign('keyword',$keyword);
        $this->assign('start',$start);
        $this->assign('end',$end);
        return $this->fetch();
    }
}